/*********************************************************
**
**   All Copyrights Reserved by Yuga Software. 2012
**
*********************************************************/
package controllers.commands
{
	import com.google.maps.LatLng;
	
	import mx.logging.ILogger;
	
	import controllers.commands.base.ICommand;
	
	import model.protocal.LocalGLMProtocal;
	import model.protocal.base.IProtocol;
	import model.validator.DeviceUtil;
	import model.vo.TestParserContext;
	
	import utils.LogUtil;
	
	import view.MapCanvas;
	
	/***
	 *  文件名: TestParseLocCommand.as
	 *  简介:  17a 测试提交基站
	 *  作者:  kant
	 *  时间:  Jan 16, 2013 11:00:20 PM
	 *
	 **/
	public class TestParseLocCommand implements ICommand
	{
		private var context : TestParserContext ;
		public static var NAME : String = "TestParseLocCommand.as";
		private var log:ILogger =  LogUtil.getInst().getLogger( NAME );
		
		private static var GSM_URL : String = "";
		
		public function TestParseLocCommand(context:Object)
		{
			this.context = TestParserContext(context);
		}
		
		public function setContext(context:Object):void
		{
		}
		
		public function execute():void
		{
			var currentData : Object = this.context.mapData.map;//点数据
			
			if (currentData != null/* && DeviceUtil.getDeviceType() == 7*/) {//LM 0608 暂时处理:解决定位功能无效的BUG
				//判断personal_status是否为0
				//获取最后一条记录
				var maxIndex:int = currentData.length -1;
				var lastLocInfo:Object = currentData[maxIndex];
				if ( lastLocInfo.personal_status==0 && 
					!(parseInt(lastLocInfo.station_info, 16)==0 && (DeviceUtil.getDeviceType()==7 || DeviceUtil.getDeviceType()==18)) ) 
				{
					var stationInfo:String = lastLocInfo.station_info;
					var prex:int = 4;
					var endx:int = 4;
					var len:int = stationInfo.length;
					var lac:String = Number("0x" + stationInfo.substr(0, prex)).toString(10);
					var cid:String = Number("0x" + stationInfo.substr(endx, len)).toString(10);
					var protocal:IProtocol = new LocalGLMProtocal(lac, cid, this.context);
					var parser:ParseMobileInfoCommand = new ParseMobileInfoCommand(protocal);
					parser.execute();	
				//如果是1，gps有效，	
				} else {
					var mapCanvas:MapCanvas = this.context.mapCanvas;
					var endLatLng:LatLng = new LatLng(currentData[0].latitude, currentData[0].longitude);
					mapCanvas.setMarker(endLatLng);	
				} 
			}
		}
	}
}